package com.team.common.dynamic;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.ApplicationContext;

public class AutoRegisterContainer  {

    private final ApplicationContext applicationContext;

    private final CustomerBuilderBean customerBuilderBean;

    public AutoRegisterContainer(ApplicationContext applicationContext, CustomerBuilderBean customerBuilderBean) {
        this.applicationContext = applicationContext;
        this.customerBuilderBean = customerBuilderBean;
    }

    public void registerBean(){
        DefaultListableBeanFactory defaultListableBeanFactory =
                (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();

        customerBuilderBean.build(defaultListableBeanFactory);
    }

    public void submitRegister(DataSourceProperties dataSourceProperties){
        DefaultListableBeanFactory defaultListableBeanFactory =
                (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
        customerBuilderBean.build(defaultListableBeanFactory,dataSourceProperties);
    }

}
